/*
 * Powered By fanrenqij.com
 * Since 2017 - 2017
 */

package com.fanrenqiji.modules.business.parent.web;


import com.fanrenqiji.common.config.GlobalSetting;
import com.fanrenqiji.common.persistence.Page;
import com.fanrenqiji.common.web.BaseController;
import com.fanrenqiji.modules.business.parent.service.ParentService;
import com.fanrenqiji.modules.business.parent.vo.ParentVO;
import com.fanrenqiji.modules.business.parent.vo.StudentVO;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value = "/live")
public class ParentLoginController extends BaseController {

    private static Logger log = LoggerFactory.getLogger(ParentLoginController.class);
    @Autowired
    private ParentService parentService;



    @ResponseBody
    @RequestMapping(value = "login")
    public Map login(String viewername, String viewertoken) {
        Map map = new HashMap();
        ParentVO parentVO = parentService.getByPhone(viewername);
        if (parentVO != null && parentVO.getPhone().equals(viewertoken)) {
            map.put("result", "ok");
            map.put("message", "登陆成功");
            if (parentVO.getStudents() != null) {
                StudentVO student = parentVO.getStudents().get(0);
                student.setAvatar(parentVO.getPortrait());
                map.put("user", student);
            }
            return map;
        } else {
            map.put("result", "error");
            map.put("message", "用户不存在");
            map.put("user", null);
            return map;
        }
    }
}